#define _CRT_SECURE_NO_WARNINGS
#include"stack.h"
void StInit(st* s)
{
	assert(s);
	s->capacity = s->top = 0;
	s->p = NULL;
}
void StPush(st* s, Datetype x)
{
	assert(s);
	if (s->capacity == s->top) {
		int newcapacity = s->capacity == 0 ? 4 : s->capacity * 2;
		Datetype* ptr = (Datetype*)realloc(s->p, newcapacity*sizeof(Datetype));
		if (ptr == NULL) {
			perror("realloc fail");
			return;
		}
		s->p = ptr;
		s->capacity = newcapacity;
	}
	s->p[s->top++] = x;
}
void StPop(st* s)
{
	assert(s);
	assert(s->top > 0);
	s->top--;
}
void StDestroy(st* s)
{
	assert(s);
	free(s->p);
	s->p = NULL;
	s->top = s->capacity = 0;
}
bool JudgeEmpty(st* s)
{
	if (s->top == 0) {
		return false;
	}
	else {
		return true;
	}
}
Datetype GetTop(st* s)
{
	assert(s);
	assert(s->top != 0);
	return s->p[s->top-1];
}